gtkplacessidebar: avoid to use a freed string
authorCarlos Soriano <csoriano@gnome.org>
Thu, 24 Sep 2015 13:54:15 +0000 (15:54 +0200)
committerCarlos Soriano <csoriano@gnome.org>
Fri, 25 Sep 2015 14:10:32 +0000 (16:10 +0200)
The string we were using is the representation of the internal text
in the popover entry. However that can be freed before setting the
bookmark label, if i.e. the row is destroyed and therefore the popover
as well.
To avoid that, duplicate the label in a local variable.

One of the consequences is that for those people using development version
we migth screwed its bookmarks file, since the bookmark manager wrote
garbage from the already freed label.

https://bugzilla.gnome.org/show_bug.cgi?id=755215

gtk/gtkplacessidebar.c

index 1ed8abe6940e77a5dbd9f04d021718bd8ed43baa..2ee7e9e86d9688ec8599ecad2ac316fd0b11d209 100644 (file)
@@ -2397,10 +2397,10 @@ static void
 do_rename (GtkButton        *button,
            GtkPlacesSidebar *sidebar)
 {
-  const gchar *new_text;
+  gchar *new_text;
   GFile *file;
 
-  new_text = gtk_entry_get_text (GTK_ENTRY (sidebar->rename_entry));
+  new_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (sidebar->rename_entry)));
 
   file = g_file_new_for_uri (sidebar->rename_uri);
   if (!_gtk_bookmarks_manager_has_bookmark (sidebar->bookmarks_manager, file))
@@ -2409,6 +2409,7 @@ do_rename (GtkButton        *button,
   _gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, file, new_text, NULL);
 
   g_object_unref (file);
+  g_free (new_text);
 
   g_clear_pointer (&sidebar->rename_uri, g_free);